package com.ssyc.student.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.student.R;
import com.ssyc.student.bean.StAnswerInfo;

import java.util.List;

/**
 * 学生端--词汇检测界面--选择图片的列表适配器
 * Created by Administrator on 2018/5/14 0014.
 */

public class StLvVocabularyPrepareAdapter extends CommonAdapter<StAnswerInfo> {

    private Context context;

    //正确答案的位置
    private String rightAnswer;

    public StLvVocabularyPrepareAdapter(Context context, List<StAnswerInfo> datas, int layoutId, String rightAnswer) {
        super(context, datas, layoutId);
        this.context = context;
        this.rightAnswer = rightAnswer;
    }

    @Override
    public void convert(ViewHolder holder, StAnswerInfo answerInfo) {

        //设置序号ABCDE
        TextView tvAnswerFlag = holder.getView(R.id.tv_answer_flag);
        tvAnswerFlag.setText(answerInfo.answerFlag);

        //设置问题的内容
        TextView tvAnswerContent = holder.getView(R.id.tv_answer_content);
        tvAnswerContent.setText(answerInfo.answerContent);

        //显示对错的遮罩层视图
        View viewState = holder.getView(R.id.view_state);

        if (answerInfo.isSelect) {
            //当前答案被选中
            tvAnswerFlag.setTextColor(context.getResources().getColor(R.color.white));
            tvAnswerFlag.setBackgroundResource(R.drawable.st_answer_select_bg);
            //选中显示遮罩层
            viewState.setVisibility(View.VISIBLE);

            //设置遮罩层的背景图,需要通过跟正确答案或者位置进行比对后确定,这里模拟正确位置
            if (answerInfo.getAnswerContent().replaceAll(" ", "").equals(rightAnswer.replaceAll(" ", ""))) {
                viewState.setBackgroundResource(R.drawable.st_img_right);
            } else {
                viewState.setBackgroundResource(R.drawable.st_img_error);
            }

        } else {
            //当前答案未被选中
            tvAnswerFlag.setTextColor(context.getResources().getColor(R.color.st_answer_normal));
            tvAnswerFlag.setBackgroundResource(R.drawable.st_answer_normal_bg);
            //未选择隐藏遮罩层
            viewState.setVisibility(View.GONE);
        }
    }
}
